package com.zk.spring5.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author ZK
 * @Description
 * @time 2021/5/8 10:34
 * @note
 */
@Repository
public class AccountDaoImpl implements AccountDao{
    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public int receiveMoney(Integer id,double money) {
        String sql = "update t_account set money=money+? where id=?";
        return jdbcTemplate.update(sql,money,id);
    }

    @Override
    public int payMoney(Integer id,double money) {
        String sql = "update t_account set money=money-? where id=?";
        return jdbcTemplate.update(sql,money,id);
    }

    @Override
    public int changeMoney(Integer id, double money) {
        // 简单起见，不考虑范围问题。
        String sql = "update t_account set money=money+? where id=?";
        return jdbcTemplate.update(sql,money,id);
    }


}
